package ylsb.service;


import org.springframework.stereotype.Service;
import ylsb.dao.DailiangchuangxinMapper;
import ylsb.model.Dailiangchuangxin;
import ylsb.model.DailiangchuangxinExample;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class DailiangchuangxinService {

    @Resource
    DailiangchuangxinMapper ddMapper;

    public List<Map<String, Object>> findBiaojuelist(String mmxiangmuId, String mmuserId){

        return ddMapper.findBiaojuelist(mmxiangmuId,mmuserId);
    }

    public List<Map<String, Object>> findChuangxinBiaojueByXiangmuId(String ppxiangmuId,String ppUserId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findChuangxinBiaojueByXiangmuId(ppxiangmuId,ppUserId,mmStartIndex,ppPageSize);
    }

    public Integer countChuangxinBiaojueByXiangmuId(String ppXiangmuId,String ppUserId) {
        Object mmCount = ddMapper.countChuangxinBiaojueByXiangmuId(ppXiangmuId,ppUserId);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public boolean deleteByxiangmuId(String xiangmuId){
        DailiangchuangxinExample mmExample=new DailiangchuangxinExample();
        DailiangchuangxinExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.deleteByExample(mmExample)>=0;
    }

    public List<Map<String, Object>> findDailiangchuangxinByXiangmuId(String ppxiangmuId,int ppPageIndex, int ppPageSize){
        int mmStartIndex = (ppPageIndex - 1) * ppPageSize;
        return ddMapper.findDailiangchuangxinByXiangmuId(ppxiangmuId,mmStartIndex,ppPageSize);
    }

    public Integer getChuangxinCount(String ppXiangmuId) {
        Object mmCount = ddMapper.countChuangxinByXiangmuId(ppXiangmuId);
        return mmCount == null ? 0 : Integer.parseInt(mmCount.toString());
    }

    public boolean isexistByxiangmuId(String xiangmuId){
        DailiangchuangxinExample mmExample=new DailiangchuangxinExample();
        DailiangchuangxinExample.Criteria criteria=mmExample.createCriteria();
        criteria.andXiangmuidEqualTo(xiangmuId);
        return  ddMapper.selectByExample(mmExample).size()>0;
    }

    public boolean add (Dailiangchuangxin ddDailiangchuangxin){
        return ddMapper.insert(ddDailiangchuangxin)==1;
    }

    public List<Dailiangchuangxin> finddailiangchuangxinlist(String xiangmuId){
        DailiangchuangxinExample mmExample=new DailiangchuangxinExample();
        mmExample.createCriteria().andXiangmuidEqualTo(xiangmuId);
        mmExample.setOrderByClause("ordernumber ASC");
        return  ddMapper.selectByExample(mmExample);

    }

}
